package oakclub.service;

import oakclub.entity.FriendEntity;
import oakclub.global.Container;
import oakclub.model.FriendModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

public class FriendService
{
    private final Logger logger = LoggerFactory.getLogger(BlockService.class);

    public void updateFriendlist(long userId) throws Exception
    {
        // get friendlist from fb
        FacebookService facebookService = (FacebookService) Container.getComponent(FacebookService.class);
        List<FriendEntity> friendlist = facebookService.getFriendlist(userId);

        // set to db
        FriendModel friendModel = (FriendModel) Container.getComponent(FriendModel.class);
        friendModel.updateFriendlist(userId, friendlist);

        // clear cache
        MemcachedService memcachedService = (MemcachedService) Container.getComponent(MemcachedService.class);
        memcachedService.delete(MemcachedService.Key.FRIEND_IDS, userId);
        memcachedService.delete(MemcachedService.Key.FRIEND_INFOS, userId);
    }
}
